﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SviluppoDistinta.Library;

namespace SviluppoDistinta.WinApp
{
    public partial class DatiParti : Form
    {
        private BindingList<Parte> listaParti;
        private ListBox lstParti;

        public DatiParti(BindingList<Parte> listaParti, ListBox lstParti)
        {
            InitializeComponent();
            this.listaParti = listaParti;
            parteBindingSource.DataSource = this.listaParti;
            this.lstParti = lstParti;
        }

        private void DatiParti_Load(object sender, EventArgs e)
        {
            cmbPartiDefault.DataSource = Parte.ListaPartiDefault;
            cmbPartiDefault.SelectedText = "";
            //grdParti.DataSource = listaParti;
            //grdParti.Columns[0].Width = 60;
            //grdParti.Columns[1].Width = 30;
            //grdParti.Columns[2].Width = 30;
            //grdParti.Columns[3].Width = 30;
            //grdParti.Columns[4].Width = 30;
            //grdParti.Columns[5].Width = 30;

        }


        private void btnAdd_Click(object sender, EventArgs e)
        {
            Parte p = (Parte)((Parte)cmbPartiDefault.SelectedItem).Clone();
            listaParti.Add(p);
        }

        private void grdParti_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            if (e.Exception is System.FormatException)
            {
                MessageBox.Show("Dato non consentito");
            }
            else
            {
                MessageBox.Show(e.Exception.Message);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void grdParti_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            lstParti.Refresh();
        }

        private void cmbPartiDefault_MouseUp(object sender, MouseEventArgs e)
        {
            //Parte p = (Parte)((Parte)cmbPartiDefault.SelectedItem).Clone();
            //listaParti.Add(p);

        }

        private void cmbPartiDefault_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Parte p = (Parte)((Parte)cmbPartiDefault.SelectedItem).Clone();
            //listaParti.Add(p);
            //cmbPartiDefault.SelectedText = "";

        }

    }
}
